package merisis.experiments.gcs;

public abstract class AbstractGuessComplemetSearch {

	public GCSEInstrument instrument = new GCSEInstrument(this.getClass().getSimpleName(), 0);

	protected long[] data = null;

	public long search(long start, long end, long key) {
		instrument.connect();
		try {
			return searchAlgoritm(start, end, key);
		} finally {
			instrument.shutdown();
		}
	}

	abstract protected long searchAlgoritm(long start, long end, long key);

	public long access(long idx) {

		instrument.doAccess();

		return data[(int) idx];
	}

	public void setData(long[] data) {

		this.data = data;

		int scale = (int) (Math.log(data.length) / Math.log(2)) + 1;
		instrument = new GCSEInstrument(this.getClass().getSimpleName(), scale);
	}
	
	public void printResult() {
		
		instrument.print();
	}
}